<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="学员姓名" prop="studentName">
        <el-input
          style="width: 150px"
          v-model="queryParams.studentName"
          placeholder="请输入学员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phonenumber">
        <el-input
          style="width: 150px"
          v-model="queryParams.phonenumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件编号" prop="idNumber">
        <el-input
          style="width: 150px"
          v-model="queryParams.idNumber"
          placeholder="请输入证件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="qualification">
        <el-select
          style="width: 150px"
          v-model="queryParams.qualification"
          placeholder="请选择学历"
          clearable
        >
          <el-option
            v-for="dict in dict.type.pxzx_xl"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="注册时间">
        <el-date-picker
          v-model="dateRange2"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:students:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['training:students:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:students:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['training:students:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- <el-table
      v-loading="loading"
      :data="studentsList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学员id" align="center" prop="studentId" />
      <el-table-column label="学员姓名" align="center" prop="studentName" />
      <el-table-column label="人员类型" align="center" prop="userType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rylx" :value="scope.row.userType" />
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" prop="phonenumber" />
      <el-table-column label="用户邮箱" align="center" prop="email" />
      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="证件类型" align="center" prop="documentType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pxzx_zjlx"
            :value="scope.row.documentType"
          />
        </template>
      </el-table-column>
      <el-table-column label="证件编号" align="center" prop="idNumber" />
      <el-table-column
        label="出生年月"
        align="center"
        prop="birthDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="证件有效期开始时间"
        align="center"
        prop="certificateStarttime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.certificateStarttime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="证件有效期结束时间"
        align="center"
        prop="certificateEndtime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.certificateEndtime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="nation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pub_mz" :value="scope.row.nation" />
        </template>
      </el-table-column>
      <el-table-column label="职务" align="center" prop="position" />
      <el-table-column label="学历" align="center" prop="qualification">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pxzx_xl"
            :value="scope.row.qualification"
          />
        </template>
      </el-table-column>
      <el-table-column label="毕业院校" align="center" prop="graduatedFrom" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="联系地址" align="center" prop="address" />
      <el-table-column label="邮政编码" align="center" prop="postCode" />
      <el-table-column label="传真" align="center" prop="fax" />
      <el-table-column label="" align="center" prop="exampleOne" />
      <el-table-column label="" align="center" prop="exampleTwo" />
      <el-table-column label="" align="center" prop="exampleThree" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:students:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:students:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table> -->
    <el-table
      v-loading="loading"
      :data="studentsList"
      @selection-change="handleSelectionChange"
      :header-cell-style="{
        'background-color': '#f5f7fa',
        'font-weight': 'bold',
        'border-bottom': '1px solid #e5e7eb',
      }"
      :cell-style="{ 'border-bottom': '1px solid #f2f3f5' }"
    >
      <!-- 选择列 -->
      <el-table-column
        type="selection"
        width="55"
        align="center"
        fixed="left"
      />
      <el-table-column
        label="序号"
        type="index"
        width="50"
        fixed="left"
        align="center"
      >
      </el-table-column>

      <!-- 核心信息列 -->
      <!-- <el-table-column
        label="学员ID"
        align="center"
        prop="studentId"
        width="100"
        fixed="left"
      /> -->
      <el-table-column
        label="学员姓名"
        align="center"
        prop="studentName"
        width="120"
        fixed="left"
      />
      <el-table-column
        label="人员类型"
        align="center"
        prop="userType"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rylx" :value="scope.row.userType" />
        </template>
      </el-table-column>
      <el-table-column
        label="手机号码"
        align="center"
        prop="phonenumber"
        width="130"
      />
      <el-table-column
        label="用户邮箱"
        align="center"
        prop="email"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column label="用户性别" align="center" prop="sex" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>

      <!-- 证件信息列 -->
      <el-table-column
        label="证件类型"
        align="center"
        prop="documentType"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pxzx_zjlx"
            :value="scope.row.documentType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="证件编号"
        align="center"
        prop="idNumber"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        label="出生年月"
        align="center"
        prop="birthDate"
        width="130"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.birthDate, "{y}-{m}-{d}") || "-"
          }}</span>
        </template>
      </el-table-column>

      <!-- 证件有效期列 -->
      <el-table-column
        label="证件有效期开始"
        align="center"
        prop="certificateStarttime"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.certificateStarttime, "{y}-{m}-{d}") || "-"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="证件有效期结束"
        align="center"
        prop="certificateEndtime"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.certificateEndtime, "{y}-{m}-{d}") || "-"
          }}</span>
        </template>
      </el-table-column>

      <!-- 其他信息列 -->
      <el-table-column label="民族" align="center" prop="nation" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pub_mz" :value="scope.row.nation" />
        </template>
      </el-table-column>
      <el-table-column
        label="职务"
        align="center"
        prop="position"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="学历"
        align="center"
        prop="qualification"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pxzx_xl"
            :value="scope.row.qualification"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="毕业院校"
        align="center"
        prop="graduatedFrom"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        label="专业"
        align="center"
        prop="major"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column
        label="联系地址"
        align="center"
        prop="address"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="邮政编码"
        align="center"
        prop="postCode"
        width="120"
      />
      <el-table-column
        label="传真"
        align="center"
        prop="fax"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="附加信息1"
        align="center"
        prop="exampleOne"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="附加信息2"
        align="center"
        prop="exampleTwo"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="附加信息3"
        align="center"
        prop="exampleThree"
        width="120"
        show-overflow-tooltip
      /> -->
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        width="180"
        show-overflow-tooltip
      />

      <!-- 操作列（固定在右侧） -->
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="140"
        class-name="table-operation"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:students:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:students:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学员对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学员姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学员姓名" />
        </el-form-item>
        <el-form-item label="人员类型" prop="userType">
          <el-select v-model="form.userType" placeholder="请选择人员类型">
            <el-option
              v-for="dict in dict.type.rylx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="用户邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入用户邮箱" />
        </el-form-item>
        <el-form-item label="用户性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="证件类型" prop="documentType">
          <el-select v-model="form.documentType" placeholder="请选择证件类型">
            <el-option
              v-for="dict in dict.type.pxzx_zjlx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件编号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入证件编号" />
        </el-form-item>
        <el-form-item label="出生年月" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生年月">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="证件有效期开始时间" prop="certificateStarttime">
          <el-date-picker clearable
            v-model="form.certificateStarttime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择证件有效期开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="证件有效期结束时间" prop="certificateEndtime">
          <el-date-picker clearable
            v-model="form.certificateEndtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择证件有效期结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-select v-model="form.nation" placeholder="请选择民族">
            <el-option
              v-for="dict in dict.type.pub_mz"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="职务" prop="position">
          <el-input v-model="form.position" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="学历" prop="qualification">
          <el-select v-model="form.qualification" placeholder="请选择学历">
            <el-option
              v-for="dict in dict.type.pxzx_xl"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="毕业院校" prop="graduatedFrom">
          <el-input v-model="form.graduatedFrom" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="联系地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入联系地址" />
        </el-form-item>
        <el-form-item label="邮政编码" prop="postCode">
          <el-input v-model="form.postCode" placeholder="请输入邮政编码" />
        </el-form-item>
        <el-form-item label="传真" prop="fax">
          <el-input v-model="form.fax" placeholder="请输入传真" />
        </el-form-item>
        <el-form-item label="留痕状态" prop="isTrace">
          <el-input v-model="form.isTrace" placeholder="请输入留痕状态" />
        </el-form-item>
        <el-form-item label="" prop="exampleOne">
          <el-input v-model="form.exampleOne" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="exampleTwo">
          <el-input v-model="form.exampleTwo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="exampleThree">
          <el-input v-model="form.exampleThree" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <div
        class="form-container"
        style="max-height: 600px; overflow-y: auto; padding-right: 10px"
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <!-- 基本信息分组 -->
          <div class="form-group">
            <h3 class="group-title">基本信息</h3>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="学员姓名" prop="studentName">
                  <el-input
                    v-model="form.studentName"
                    placeholder="请输入学员姓名"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="人员类型" prop="userType">
                  <el-select
                    v-model="form.userType"
                    placeholder="请选择人员类型"
                  >
                    <el-option
                      v-for="dict in dict.type.rylx"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="手机号码" prop="phonenumber">
                  <el-input
                    v-model="form.phonenumber"
                    placeholder="请输入手机号码"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="用户邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入用户邮箱" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="用户性别" prop="sex">
                  <el-radio-group v-model="form.sex">
                    <el-radio
                      v-for="dict in dict.type.sys_user_sex"
                      :key="dict.value"
                      :label="dict.value"
                      >{{ dict.label }}</el-radio
                    >
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生年月" prop="birthDate">
                  <el-date-picker
                    clearable
                    v-model="form.birthDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择出生年月"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="民族" prop="nation">
                  <el-select v-model="form.nation" placeholder="请选择民族">
                    <el-option
                      v-for="dict in dict.type.pub_mz"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职务" prop="position">
                  <el-input v-model="form.position" placeholder="请输入职务" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 证件信息分组 -->
          <div class="form-group">
            <h3 class="group-title">证件信息</h3>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="证件类型" prop="documentType">
                  <el-select
                    v-model="form.documentType"
                    placeholder="请选择证件类型"
                  >
                    <el-option
                      v-for="dict in dict.type.pxzx_zjlx"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件编号" prop="idNumber">
                  <el-input
                    v-model="form.idNumber"
                    placeholder="请输入证件编号"
                  />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item
                  label="证件有效期开始时间"
                  prop="certificateStarttime"
                >
                  <el-date-picker
                    clearable
                    v-model="form.certificateStarttime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择证件有效期开始时间"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="证件有效期结束时间"
                  prop="certificateEndtime"
                >
                  <el-date-picker
                    clearable
                    v-model="form.certificateEndtime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择证件有效期结束时间"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row> -->
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="证件有效期" prop="certificateValidity">
                  <el-date-picker
                    clearable
                    v-model="dateRange"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    @change="handleDateRangeChange"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 教育信息分组 -->
          <div class="form-group">
            <h3 class="group-title">教育信息</h3>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="学历" prop="qualification">
                  <el-select
                    v-model="form.qualification"
                    placeholder="请选择学历"
                  >
                    <el-option
                      v-for="dict in dict.type.pxzx_xl"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="毕业院校" prop="graduatedFrom">
                  <el-input
                    v-model="form.graduatedFrom"
                    placeholder="请输入毕业院校"
                  />
                </el-form-item>
              </el-col>
            </el-row>

            <el-form-item label="专业" prop="major">
              <el-input v-model="form.major" placeholder="请输入专业" />
            </el-form-item>
          </div>

          <!-- 联系信息分组 -->
          <div class="form-group">
            <h3 class="group-title">联系信息</h3>
            <el-form-item label="联系地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入联系地址" />
            </el-form-item>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="邮政编码" prop="postCode">
                  <el-input
                    v-model="form.postCode"
                    placeholder="请输入邮政编码"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="传真" prop="fax">
                  <el-input v-model="form.fax" placeholder="请输入传真" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 其他信息分组 -->
          <div class="form-group">
            <h3 class="group-title">其他信息</h3>
            <!-- <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="删除标志" prop="delFlag">
                  <el-input
                    v-model="form.delFlag"
                    placeholder="请输入删除标志"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="留痕状态" prop="isTrace">
                  <el-input
                    v-model="form.isTrace"
                    placeholder="请输入留痕状态"
                  />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="附加信息1" prop="exampleOne">
                  <el-input v-model="form.exampleOne" placeholder="请输入" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="附加信息2" prop="exampleTwo">
                  <el-input v-model="form.exampleTwo" placeholder="请输入" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="附加信息3" prop="exampleThree">
                  <el-input v-model="form.exampleThree" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row> -->

            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                rows="3"
              />
            </el-form-item>
          </div>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStudents,
  getStudents,
  delStudents,
  addStudents,
  updateStudents,
  delStudentsWithUser,
  addStudentsWithUser,
  updateStudentsWithUser,
} from "@/api/training/students";

export default {
  name: "Students",
  dicts: ["rylx", "pub_mz", "pxzx_xl", "sys_user_sex", "pxzx_zjlx"],
  data() {
    return {
      // 日期范围数组 [startDate, endDate]
      dateRange: [],
      dateRange2: [],
      form: {
        // 保持原有的数据结构
        certificateStarttime: "",
        certificateEndtime: "",
        // 其他表单字段...
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学员表格数据
      studentsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: null,
        phonenumber: null,
        idNumber: null,
        qualification: null,
        createTime: null,
      },
      // 表单参数
      // form: {},
      // 表单校验
      rules: {
        studentName: [
          { required: true, message: "学员姓名不能为空", trigger: "blur" },
        ],
        phonenumber: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
        ],
        sex: [
          { required: true, message: "用户性别不能为空", trigger: "change" },
        ],
        documentType: [
          { required: true, message: "证件类型不能为空", trigger: "change" },
        ],
        idNumber: [
          { required: true, message: "证件编号不能为空", trigger: "blur" },
        ],
        birthDate: [
          { required: true, message: "出生年月不能为空", trigger: "blur" },
        ],
        qualification: [
          { required: true, message: "学历不能为空", trigger: "change" },
        ],
        address: [
          { required: true, message: "联系地址不能为空", trigger: "blur" },
        ],
        postCode: [
          { required: true, message: "邮政编码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 处理日期范围变化，同步到原有的表单字段
    handleDateRangeChange(range) {
      if (range && range.length === 2) {
        this.form.certificateStarttime = range[0];
        this.form.certificateEndtime = range[1];
      } else {
        this.form.certificateStarttime = "";
        this.form.certificateEndtime = "";
      }
    },
    /** 查询学员列表 */
    getList() {
      this.loading = true;
      listStudents(this.addDateRange(this.queryParams, this.dateRange2)).then(
        (response) => {
          this.studentsList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.dateRange = [];
      this.form = {
        studentId: null,
        studentName: null,
        userType: null,
        phonenumber: null,
        email: null,
        sex: null,
        status: null,
        delFlag: null,
        documentType: null,
        idNumber: null,
        birthDate: null,
        certificateStarttime: null,
        certificateEndtime: null,
        nation: null,
        position: null,
        qualification: null,
        graduatedFrom: null,
        major: null,
        address: null,
        postCode: null,
        fax: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isTrace: null,
        exampleOne: null,
        exampleTwo: null,
        exampleThree: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange2 = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.studentId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员";
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const studentId = row.studentId || this.ids;
    //   getStudents(studentId).then((response) => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改学员";
    //   });
    // },
    handleUpdate(row) {
      this.reset();
      const studentId = row.studentId || this.ids;
      getStudents(studentId).then((response) => {
        // 给表单赋值
        this.form = response.data;
        // 关键修复：同步日期范围到dateRange，实现回显
        this.dateRange = [
          response.data.certificateStarttime,
          response.data.certificateEndtime,
        ].filter(Boolean); // 过滤空值，避免出现[null, null]导致的问题
        this.open = true;
        this.title = "修改学员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        console.log("this.form = " + this.form);
        if (valid) {
          if (this.form.studentId != null) {
            updateStudentsWithUser(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentsWithUser(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const studentIds = row.studentId || this.ids;
      this.$modal
        .confirm('是否确认删除学员编号为"' + studentIds + '"的数据项？')
        .then(function () {
          return delStudentsWithUser(studentIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "training/students/export",
        {
          ...this.queryParams,
        },
        `students_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.form-group {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px dashed #e5e6eb;
}

.form-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.group-title {
  margin-bottom: 15px;
  padding-left: 5px;
  font-size: 15px;
  color: #1890ff;
  border-left: 3px solid #1890ff;
}

/* 调整滚动条样式 */
.form-container::-webkit-scrollbar {
  width: 6px;
}

.form-container::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background-color: #ddd;
}

.form-container::-webkit-scrollbar-track {
  background-color: #f5f5f5;
}
</style>
